﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace Matematika.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            RunAsync().Wait();
            System.Console.ReadKey();
        }

        static async Task RunAsync()
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:8492/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

                HttpResponseMessage response = await client.GetAsync("api/Matematika/");
                if (response.IsSuccessStatusCode)
                {
                    System.Console.WriteLine(response.Content.ReadAsStringAsync().Result);
                }
                else
                {
                    System.Console.WriteLine(response.StatusCode);
                }

                System.Console.WriteLine();

                response = await client.GetAsync("api/Matematika/3");
                if (response.IsSuccessStatusCode)
                {
                    System.Console.WriteLine(response.Content.ReadAsStringAsync().Result);
                }
                else
                {
                    System.Console.WriteLine(response.StatusCode);
                }

                System.Console.WriteLine();

                response = await client.GetAsync("api/Matematika?op=tambah&bil1=13&bil2=23");
                if (response.IsSuccessStatusCode)
                {
                    System.Console.WriteLine(response.Content.ReadAsStringAsync().Result);
                }
                else
                {
                    System.Console.WriteLine(response.StatusCode);
                }
            }
        }
    }
}
